﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace ProjectSem40701.Admin
{
    public partial class Article : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ArticleStatusLabel_DataBinding(object sender, EventArgs e)
        {
            try
            {
                Label ArticleStatusLabel = sender as Label;
                ArticleStatusLabel.Text = ArticleStatusLabel.Text == "1" ? "Kích hoạt" : "Khóa";
            }
            catch
            { 
                //bao that 
            }

        }

        protected void cbbStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                DropDownList cbbStatus = sender as DropDownList;
                if (cbbStatus.SelectedValue.ToString() != "-1")
                {
                    this.rgrArticle.MasterTableView.GetColumn("ArticleStatus").CurrentFilterValue 
                        = cbbStatus.SelectedValue;
                    GridFilteringItem filterItem 
                        = this.rgrArticle.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
                    filterItem.FireCommandEvent("Filter", new Pair("EqualTo", "ArticleStatus"));

                }
                else
                {
                    GridFilteringItem filterItem = this.rgrArticle.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
                    filterItem.FireCommandEvent("Filter", new Pair("NoFilter", "ArticleStatus"));  
                }
                this.lblSelectedIndex.Text = cbbStatus.SelectedValue.ToString();
            }
            catch (Exception exc)
            {
                exc.ToString();
            }
        }

        protected void cbbStatus_PreRender(object sender, EventArgs e)
        {
            DropDownList cbbStatus = (DropDownList)sender;
            foreach (ListItem item in cbbStatus.Items)
            {
                if (item.Value.ToString() == this.lblSelectedIndex.Text.ToString())
                {
                    item.Selected = true;
                }
            }
        }

        protected void lblDescription_DataBinding(object sender, EventArgs e)
        {
            Label lblDesc = sender as Label;
            lblDesc.Text = Server.HtmlDecode(lblDesc.Text);
        }
    }
}
